package com.entity;

import java.sql.Timestamp;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * TRestaurant entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.entity.TRestaurant
 * @author MyEclipse Persistence Tools
 */

public class TRestaurantDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(TRestaurantDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String INTRODUCTION = "introduction";
	public static final String CHARACTERISTICS = "characteristics";
	public static final String ADDRESS = "address";
	public static final String TELEPHONE = "telephone";
	public static final String BUS_ROUTE = "busRoute";
	public static final String STATE = "state";
	public static final String SORT_NO = "sortNo";
	public static final String IS_SHOW = "isShow";
	public static final String IS_CHARGE_ORDER = "isChargeOrder";
	public static final String PARENT_ID = "parentId";
	public static final String TABLE_COUNT = "tableCount";
	public static final String TAREA_ID = "tareaId";

	protected void initDao() {
		// do nothing
	}

	public void save(TRestaurant transientInstance) {
		log.debug("saving TRestaurant instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TRestaurant persistentInstance) {
		log.debug("deleting TRestaurant instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TRestaurant findById(java.lang.String id) {
		log.debug("getting TRestaurant instance with id: " + id);
		try {
			TRestaurant instance = (TRestaurant) getHibernateTemplate().get(
					"com.entity.TRestaurant", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TRestaurant instance) {
		log.debug("finding TRestaurant instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TRestaurant instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TRestaurant as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntroduction(Object introduction) {
		return findByProperty(INTRODUCTION, introduction);
	}

	public List findByCharacteristics(Object characteristics) {
		return findByProperty(CHARACTERISTICS, characteristics);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByTelephone(Object telephone) {
		return findByProperty(TELEPHONE, telephone);
	}

	public List findByBusRoute(Object busRoute) {
		return findByProperty(BUS_ROUTE, busRoute);
	}

	public List findByState(Object state) {
		return findByProperty(STATE, state);
	}

	public List findBySortNo(Object sortNo) {
		return findByProperty(SORT_NO, sortNo);
	}

	public List findByIsShow(Object isShow) {
		return findByProperty(IS_SHOW, isShow);
	}

	public List findByIsChargeOrder(Object isChargeOrder) {
		return findByProperty(IS_CHARGE_ORDER, isChargeOrder);
	}

	public List findByParentId(Object parentId) {
		return findByProperty(PARENT_ID, parentId);
	}

	public List findByTableCount(Object tableCount) {
		return findByProperty(TABLE_COUNT, tableCount);
	}

	public List findByTareaId(Object tareaId) {
		return findByProperty(TAREA_ID, tareaId);
	}

	public List findAll() {
		log.debug("finding all TRestaurant instances");
		try {
			String queryString = "from TRestaurant";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TRestaurant merge(TRestaurant detachedInstance) {
		log.debug("merging TRestaurant instance");
		try {
			TRestaurant result = (TRestaurant) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TRestaurant instance) {
		log.debug("attaching dirty TRestaurant instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TRestaurant instance) {
		log.debug("attaching clean TRestaurant instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TRestaurantDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TRestaurantDAO) ctx.getBean("TRestaurantDAO");
	}
}